define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'orderlist/index' + location.search,
                    add_url: 'orderlist/add',
                    edit_url: 'orderlist/edit',
                    del_url: 'orderlist/del',
                    multi_url: 'orderlist/multi',
                    import_url: 'orderlist/import',
                    table: 'orderlist',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goods.name', title: __('Goods_id'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('卖家'), operate: 'LIKE'},
                        {field: 'buyuser', title: __('买家'), operate: false},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'payimage', title: __('Payimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'saveimage', title: __('Saveimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'savetime', title: __('Savetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'savemoney', title: __('Savemoney'), operate:'BETWEEN'},
                        {field: 'getmoney', title: __('Getmoney'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons:  [
                                {
                                    name: 'detail',
                                    title: __('拆分订单'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-expand',
                                    extend: 'data-toggle="tooltip" title="' + __('拆分订单') + '"',
                                    url: 'orderlist/split',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status == 0){
                                            return true;
                                        }else{
                                            return false;
                                        }




                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        split: function () {
            Controller.api.bindevent();
        },
        importfile: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
